package com.example.administrator.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ExpandableListView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ExpandableListView mExpandListView;
    private static final String[] GROUP_NAME = new String[]{"娱乐新闻","政治新闻","科技新闻"};
    private List<List<News>> mList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mExpandListView = (ExpandableListView) findViewById(R.id.expand_listView);
        mExpandListView.setAdapter(getAdapter());
    }
    private MyExpandableAdapter getAdapter(){
        mList = new ArrayList<>();
        for (int i = 0; i <GROUP_NAME.length ; i++) {
            List<News> newsList = new ArrayList<>();
            for (int j = 0; j < 10 ; j++) {
                News news = new News(R.mipmap.ic_launcher,"新闻标题"+j,"这是新闻的概要"+j);
                newsList.add(news);
            }
            mList.add(newsList);
        }
        MyExpandableAdapter adapter = new MyExpandableAdapter(this,mList,GROUP_NAME);
        return adapter;
    }
}
